home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / drivers / blockhl.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  13KB  |  391 lines

  1. /***************************************************************************
  2.  
  3. Block Hole (GX973) (c) 1989 Konami
  4.  
  5. driver by Nicola Salmoria
  6.  
  7. Notes:
  8. Quarth works, but Block Hole crashes when it reaches the title screen. An
  9. interrupt happens, and after rti the ROM bank is not the same as before so
  10. it jumps to garbage code.
  11. If you want to see this happen, place a breakpoint at 0x8612, and trace
  12. after that.
  13. The code is almost identical in the two versions, it looks like Quarth is
  14. working just because luckily the interrupt doesn't happen at that point.
  15. It seems that the interrupt handler trashes the selected ROM bank and forces
  16. it to 0. To prevent crashes, I only generate interrupts when the ROM bank is
  17. already 0. There might be another interrupt enable register, but I haven't
  18. found it.
  19.  
  20. ***************************************************************************/
  21.  
  22. #include "driver.h"
  23. #include "vidhrdw/generic.h"
  24. #include "cpu/konami/konami.h" /* for the callback and the firq irq definition */
  25. #include "vidhrdw/konamiic.h"
  26.  
  27. /* prototypes */
  28. static void blockhl_init_machine( void );
  29. static void blockhl_banking( int lines );
  30.  
  31.  
  32. void blockhl_vh_stop( void );
  33. int blockhl_vh_start( void );
  34. void blockhl_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);
  35.  
  36. static int palette_selected;
  37. static unsigned char *ram;
  38. static int rombank;
  39.  
  40. static int blockhl_interrupt( void )
  41. {
  42.     if (K052109_is_IRQ_enabled() && rombank == 0)    /* kludge to prevent crashes */
  43.         return KONAMI_INT_IRQ;
  44.     else
  45.         return ignore_interrupt();
  46. }
  47.  
  48. static READ_HANDLER( bankedram_r )
  49. {
  50.     if (palette_selected)
  51.         return paletteram_r(offset);
  52.     else
  53.         return ram[offset];
  54. }
  55.  
  56. static WRITE_HANDLER( bankedram_w )
  57. {
  58.     if (palette_selected)
  59.         paletteram_xBBBBBGGGGGRRRRR_swap_w(offset,data);
  60.     else
  61.         ram[offset] = data;
  62. }
  63.  
  64. WRITE_HANDLER( blockhl_sh_irqtrigger_w )
  65. {
  66.     cpu_cause_interrupt(1,0xff);
  67. }
  68.  
  69.  
  70.  
  71. static struct MemoryReadAddress readmem[] =
  72. {
  73.     { 0x1f94, 0x1f94, input_port_4_r },
  74.     { 0x1f95, 0x1f95, input_port_0_r },
  75.     { 0x1f96, 0x1f96, input_port_1_r },
  76.     { 0x1f97, 0x1f97, input_port_2_r },
  77.     { 0x1f98, 0x1f98, input_port_3_r },
  78.     { 0x0000, 0x3fff, K052109_051960_r },
  79.     { 0x4000, 0x57ff, MRA_RAM },
  80.     { 0x5800, 0x5fff, bankedram_r },
  81.     { 0x6000, 0x7fff, MRA_BANK1 },
  82.     { 0x8000, 0xffff, MRA_ROM },
  83.     { -1 }    /* end of table */
  84. };
  85.  
  86. static struct MemoryWriteAddress writemem[] =
  87. {
  88.     { 0x1f84, 0x1f84, soundlatch_w },
  89.     { 0x1f88, 0x1f88, blockhl_sh_irqtrigger_w },
  90.     { 0x1f8c, 0x1f8c, watchdog_reset_w },
  91.     { 0x0000, 0x3fff, K052109_051960_w },
  92.     { 0x4000, 0x57ff, MWA_RAM },
  93.     { 0x5800, 0x5fff, bankedram_w, &ram },
  94.     { 0x6000, 0x7fff, MWA_ROM },
  95.     { 0x8000, 0xffff, MWA_ROM },
  96.     { -1 }    /* end of table */
  97. };
  98.  
  99. static struct MemoryReadAddress sound_readmem[] =
  100. {
  101.     { 0x0000, 0x7fff, MRA_ROM },
  102.     { 0x8000, 0x87ff, MRA_RAM },
  103.     { 0xa000, 0xa000, soundlatch_r },
  104.     { 0xc001, 0xc001, YM2151_status_port_0_r },
  105.     { -1 }    /* end of table */
  106. };
  107.  
  108. static struct MemoryWriteAddress sound_writemem[] =
  109. {
  110.     { 0x0000, 0x7fff, MWA_ROM },
  111.     { 0x8000, 0x87ff, MWA_RAM },
  112.     { 0xc000, 0xc000, YM2151_register_port_0_w },
  113.     { 0xc001, 0xc001, YM2151_data_port_0_w },
  114.     { 0xe00c, 0xe00d, MWA_NOP },        /* leftover from missing 007232? */
  115.     { -1 }    /* end of table */
  116. };
  117.  
  118. /***************************************************************************
  119.  
  120.     Input Ports
  121.  
  122. ***************************************************************************/
  123.  
  124. INPUT_PORTS_START( blockhl )
  125.     PORT_START    /* PLAYER 1 INPUTS */
  126.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | IPF_PLAYER1 )
  127.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_PLAYER1 )
  128.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | IPF_PLAYER1 )
  129.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | IPF_PLAYER1 )
  130.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER1 )
  131.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER1 )
  132.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON3 | IPF_PLAYER1 )
  133.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START1 )
  134.  
  135.     PORT_START    /* PLAYER 2 INPUTS */
  136.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | IPF_PLAYER2 )
  137.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_PLAYER2 )
  138.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | IPF_PLAYER2 )
  139.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | IPF_PLAYER2 )
  140.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER2 )
  141.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER2 )
  142.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON3 | IPF_PLAYER2 )
  143.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START2 )
  144.  
  145.     PORT_START    /* DSW #1 */
  146.     PORT_DIPNAME( 0x0f, 0x0f, DEF_STR( Coin_A ) )
  147.     PORT_DIPSETTING(    0x02, DEF_STR( 4C_1C ) )
  148.     PORT_DIPSETTING(    0x05, DEF_STR( 3C_1C ) )
  149.     PORT_DIPSETTING(    0x08, DEF_STR( 2C_1C ) )
  150.     PORT_DIPSETTING(    0x04, DEF_STR( 3C_2C ) )
  151.     PORT_DIPSETTING(    0x01, DEF_STR( 4C_3C ) )
  152.     PORT_DIPSETTING(    0x0f, DEF_STR( 1C_1C ) )
  153.     PORT_DIPSETTING(    0x03, DEF_STR( 3C_4C ) )
  154.     PORT_DIPSETTING(    0x07, DEF_STR( 2C_3C ) )
  155.     PORT_DIPSETTING(    0x0e, DEF_STR( 1C_2C ) )
  156.     PORT_DIPSETTING(    0x06, DEF_STR( 2C_5C ) )
  157.     PORT_DIPSETTING(    0x0d, DEF_STR( 1C_3C ) )
  158.     PORT_DIPSETTING(    0x0c, DEF_STR( 1C_4C ) )
  159.     PORT_DIPSETTING(    0x0b, DEF_STR( 1C_5C ) )
  160.     PORT_DIPSETTING(    0x0a, DEF_STR( 1C_6C ) )
  161.     PORT_DIPSETTING(    0x09, DEF_STR( 1C_7C ) )
  162.     PORT_DIPSETTING(    0x00, DEF_STR( Free_Play ) )
  163.     PORT_DIPNAME( 0xf0, 0xf0, DEF_STR( Coin_B ) )
  164.     PORT_DIPSETTING(    0x20, DEF_STR( 4C_1C ) )
  165.     PORT_DIPSETTING(    0x50, DEF_STR( 3C_1C ) )
  166.     PORT_DIPSETTING(    0x80, DEF_STR( 2C_1C ) )
  167.     PORT_DIPSETTING(    0x40, DEF_STR( 3C_2C ) )
  168.     PORT_DIPSETTING(    0x10, DEF_STR( 4C_3C ) )
  169.     PORT_DIPSETTING(    0xf0, DEF_STR( 1C_1C ) )
  170.     PORT_DIPSETTING(    0x30, DEF_STR( 3C_4C ) )
  171.     PORT_DIPSETTING(    0x70, DEF_STR( 2C_3C ) )
  172.     PORT_DIPSETTING(    0xe0, DEF_STR( 1C_2C ) )
  173.     PORT_DIPSETTING(    0x60, DEF_STR( 2C_5C ) )
  174.     PORT_DIPSETTING(    0xd0, DEF_STR( 1C_3C ) )
  175.     PORT_DIPSETTING(    0xc0, DEF_STR( 1C_4C ) )
  176.     PORT_DIPSETTING(    0xb0, DEF_STR( 1C_5C ) )
  177.     PORT_DIPSETTING(    0xa0, DEF_STR( 1C_6C ) )
  178.     PORT_DIPSETTING(    0x90, DEF_STR( 1C_7C ) )
  179. //    PORT_DIPSETTING(    0x00, "Invalid" )
  180.  
  181.     PORT_START    /* DSW #2 */
  182.     PORT_DIPNAME( 0x01, 0x01, DEF_STR( Lives ) )
  183.     PORT_DIPSETTING(    0x01, "1" )
  184.     PORT_DIPSETTING(    0x00, "2" )
  185.     PORT_DIPNAME( 0x02, 0x02, DEF_STR( Unknown ) )
  186.     PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
  187.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  188.     PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unknown ) )
  189.     PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
  190.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  191.     PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) )
  192.     PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
  193.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  194.     PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unknown ) )
  195.     PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
  196.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  197.     PORT_DIPNAME( 0x60, 0x40, DEF_STR( Difficulty ) )
  198.     PORT_DIPSETTING(    0x60, "Easy" )
  199.     PORT_DIPSETTING(    0x40, "Normal" )
  200.     PORT_DIPSETTING(    0x20, "Difficult" )
  201.     PORT_DIPSETTING(    0x00, "Very Difficult" )
  202.     PORT_DIPNAME( 0x80, 0x00, DEF_STR( Demo_Sounds ) )
  203.     PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
  204.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  205.  
  206.     PORT_START    /* DSW #3 */
  207.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )
  208.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 )
  209.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN3 )
  210.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN )
  211.     PORT_DIPNAME( 0x10, 0x10, DEF_STR( Flip_Screen ) )
  212.     PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
  213.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  214.     PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unknown ) )
  215.     PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
  216.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  217.     PORT_SERVICE( 0x40, IP_ACTIVE_LOW )
  218.     PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unknown ) )
  219.     PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
  220.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  221. INPUT_PORTS_END
  222.  
  223.  
  224. /***************************************************************************
  225.  
  226.     Machine Driver
  227.  
  228. ***************************************************************************/
  229.  
  230. static struct YM2151interface ym2151_interface =
  231. {
  232.     1, /* 1 chip */
  233.     3579545, /* 3.579545 MHz */
  234.     { YM3012_VOL(60,MIXER_PAN_LEFT,60,MIXER_PAN_RIGHT) },
  235.     { 0 },
  236.     { 0 }
  237. };
  238.  
  239. static struct MachineDriver machine_driver_blockhl =
  240. {
  241.     /* basic machine hardware */
  242.     {
  243.         {
  244.             CPU_KONAMI,        /* Konami custom 052526 */
  245.             3000000,        /* ? */
  246.             readmem,writemem,0,0,
  247.             blockhl_interrupt,1
  248.         },
  249.         {
  250.             CPU_Z80 | CPU_AUDIO_CPU,
  251.             3579545,        /* ? */
  252.             sound_readmem,sound_writemem,0,0,
  253.             ignore_interrupt,0    /* interrupts are triggered by the main CPU */
  254.         }
  255.     },
  256.     60, DEFAULT_60HZ_VBLANK_DURATION,    /* frames per second, vblank duration */
  257.     1,    /* 1 CPU slice per frame - interleaving is forced when a sound command is written */
  258.     blockhl_init_machine,
  259.  
  260.     /* video hardware */
  261.     64*8, 32*8, { 14*8, (64-14)*8-1, 2*8, 30*8-1 },
  262.     0,    /* gfx decoded by konamiic.c */
  263.     1024, 1024,
  264.     0,
  265.  
  266.     VIDEO_TYPE_RASTER | VIDEO_MODIFIES_PALETTE,
  267.     0,
  268.     blockhl_vh_start,
  269.     blockhl_vh_stop,
  270.     blockhl_vh_screenrefresh,
  271.  
  272.     /* sound hardware */
  273.     0,0,0,0,
  274.     {
  275.         {
  276.             SOUND_YM2151,
  277.             &ym2151_interface
  278.         }
  279.     }
  280. };
  281.  
  282.  
  283. /***************************************************************************
  284.  
  285.   Game ROMs
  286.  
  287. ***************************************************************************/
  288.  
  289. ROM_START( blockhl )
  290.     ROM_REGION( 0x18800, REGION_CPU1 ) /* code + banked roms + space for banked RAM */
  291.     ROM_LOAD( "973l02.e21", 0x10000, 0x08000, 0xe14f849a )
  292.     ROM_CONTINUE(           0x08000, 0x08000 )
  293.  
  294.     ROM_REGION( 0x10000, REGION_CPU2 ) /* 64k for the sound CPU */
  295.     ROM_LOAD( "973d01.g6",  0x0000, 0x8000, 0xeeee9d92 )
  296.  
  297.     ROM_REGION( 0x20000, REGION_GFX1 ) /* graphics (addressable by the main CPU) */
  298.     ROM_LOAD_GFX_EVEN( "973f07.k15", 0x00000, 0x08000, 0x1a8cd9b4 )    /* tiles */
  299.     ROM_LOAD_GFX_ODD ( "973f08.k18", 0x00000, 0x08000, 0x952b51a6 )
  300.     ROM_LOAD_GFX_EVEN( "973f09.k20", 0x10000, 0x08000, 0x77841594 )
  301.     ROM_LOAD_GFX_ODD ( "973f10.k23", 0x10000, 0x08000, 0x09039fab )
  302.  
  303.     ROM_REGION( 0x20000, REGION_GFX2 ) /* graphics (addressable by the main CPU) */
  304.     ROM_LOAD_GFX_EVEN( "973f06.k12", 0x00000, 0x08000, 0x51acfdb6 )    /* sprites */
  305.     ROM_LOAD_GFX_ODD ( "973f05.k9",  0x00000, 0x08000, 0x4cfea298 )
  306.     ROM_LOAD_GFX_EVEN( "973f04.k7",  0x10000, 0x08000, 0x69ca41bd )
  307.     ROM_LOAD_GFX_ODD ( "973f03.k4",  0x10000, 0x08000, 0x21e98472 )
  308.  
  309.     ROM_REGION( 0x0100, REGION_PROMS )    /* PROMs */
  310.     ROM_LOAD( "973a11.h10", 0x0000, 0x0100, 0x46d28fe9 )    /* priority encoder (not used) */
  311. ROM_END
  312.  
  313. ROM_START( quarth )
  314.     ROM_REGION( 0x18800, REGION_CPU1 ) /* code + banked roms + space for banked RAM */
  315.     ROM_LOAD( "973j02.e21", 0x10000, 0x08000, 0x27a90118 )
  316.     ROM_CONTINUE(           0x08000, 0x08000 )
  317.  
  318.     ROM_REGION( 0x10000, REGION_CPU2 ) /* 64k for the sound CPU */
  319.     ROM_LOAD( "973d01.g6",  0x0000, 0x8000, 0xeeee9d92 )
  320.  
  321.     ROM_REGION( 0x20000, REGION_GFX1 ) /* graphics (addressable by the main CPU) */
  322.     ROM_LOAD_GFX_EVEN( "973e07.k15", 0x00000, 0x08000, 0x0bd6b0f8 )    /* tiles */
  323.     ROM_LOAD_GFX_ODD ( "973e08.k18", 0x00000, 0x08000, 0x104d0d5f )
  324.     ROM_LOAD_GFX_EVEN( "973e09.k20", 0x10000, 0x08000, 0xbd3a6f24 )
  325.     ROM_LOAD_GFX_ODD ( "973e10.k23", 0x10000, 0x08000, 0xcf5e4b86 )
  326.  
  327.     ROM_REGION( 0x20000, REGION_GFX2 ) /* graphics (addressable by the main CPU) */
  328.     ROM_LOAD_GFX_EVEN( "973e06.k12", 0x00000, 0x08000, 0x0d58af85 )    /* sprites */
  329.     ROM_LOAD_GFX_ODD ( "973e05.k9",  0x00000, 0x08000, 0x15d822cb )
  330.     ROM_LOAD_GFX_EVEN( "973e04.k7",  0x10000, 0x08000, 0xd70f4a2c )
  331.     ROM_LOAD_GFX_ODD ( "973e03.k4",  0x10000, 0x08000, 0x2c5a4b4b )
  332.  
  333.     ROM_REGION( 0x0100, REGION_PROMS )    /* PROMs */
  334.     ROM_LOAD( "973a11.h10", 0x0000, 0x0100, 0x46d28fe9 )    /* priority encoder (not used) */
  335. ROM_END
  336.  
  337.  
  338. /***************************************************************************
  339.  
  340.   Game driver(s)
  341.  
  342. ***************************************************************************/
  343.  
  344. static void blockhl_banking( int lines )
  345. {
  346.     unsigned char *RAM = memory_region(REGION_CPU1);
  347.     int offs;
  348.  
  349.     /* bits 0-1 = ROM bank */
  350.     rombank = lines & 0x03;
  351.     offs = 0x10000 + (lines & 0x03) * 0x2000;
  352.     cpu_setbank(1,&RAM[offs]);
  353.  
  354.     /* bits 3/4 = coin counters */
  355.     coin_counter_w(0,lines & 0x08);
  356.     coin_counter_w(1,lines & 0x10);
  357.  
  358.     /* bit 5 = select palette RAM or work RAM at 5800-5fff */
  359.     palette_selected = ~lines & 0x20;
  360.  
  361.     /* bit 6 = enable char ROM reading through the video RAM */
  362.     K052109_set_RMRD_line( ( lines & 0x40 ) ? ASSERT_LINE : CLEAR_LINE );
  363.  
  364.     /* bit 7 used but unknown */
  365.  
  366.     /* other bits unknown */
  367.  
  368.     if ((lines & 0x84) != 0x80) logerror("%04x: setlines %02x\n",cpu_get_pc(),lines);
  369. }
  370.  
  371. static void blockhl_init_machine( void )
  372. {
  373.     unsigned char *RAM = memory_region(REGION_CPU1);
  374.  
  375.     konami_cpu_setlines_callback = blockhl_banking;
  376.  
  377.     paletteram = &RAM[0x18000];
  378. }
  379.  
  380.  
  381. static void init_blockhl(void)
  382. {
  383.     konami_rom_deinterleave_2(REGION_GFX1);
  384.     konami_rom_deinterleave_2(REGION_GFX2);
  385. }
  386.  
  387.  
  388.  
  389. GAME( 1989, blockhl, 0,       blockhl, blockhl, blockhl, ROT0, "Konami", "Block Hole" )
  390. GAME( 1989, quarth,  blockhl, blockhl, blockhl, blockhl, ROT0, "Konami", "Quarth (Japan)" )
  391.